/** @file               sw_cfgm.h
 *  @copyright          Copyright (C) 2006-2026 flyfish (tenggui_fu@126.com)
 *  @brief              This file is part of the swallow library
 *  @author             $Author: flyfish $
 *  @version            $Rev: 385 $
 *  @date               $Date: 2016-12-22 00:12:05 +0800 (周四, 22 12月 2016) $
 */
#ifndef __SW_CFGM_H__
#define __SW_CFGM_H__

#ifdef __cplusplus
extern "C" {
#endif

typedef SW_VOID             *SW_CFG;
#define SW_INVALID_CFG      NULL

typedef SW_VOID             *SW_CFGM;
#define SW_INVALID_CFGM     NULL

typedef enum _SW_CFGM_TYPE
{
    SW_CT_INI,
    SW_CT_JSON,
    SW_CT_XML
}SW_CFGM_TYPE;

typedef SW_CFG (*SW_CFGM_OPEN_PROC)(const SW_CHAR *pFileName);
typedef SW_RET (*SW_CFGM_CLOSE_PROC)(SW_CFG cfg);
typedef SW_RET (*SW_CFGM_SAVE_PROC)(SW_CFG cfg, const SW_CHAR *pFileName);
typedef SW_RET (*SW_CFGM_READ_PROC)(SW_CFG cfg, const SW_CHAR *pFileName, const SW_CHAR *pSection, const SW_CHAR *pKey, SW_MUTEX *pMtx, SW_VOID *pData, SW_UINT32 dataLen, SW_DATA_TYPE dataType);
typedef SW_RET (*SW_CFGM_WRITE_PROC)(SW_CFG cfg, const SW_CHAR *pFileName, const SW_CHAR *pSection, const SW_CHAR *pKey, SW_MUTEX *pMtx, const SW_VOID *pData, SW_UINT32 dataLen, SW_DATA_TYPE dataType, SW_BOOL *pModified);
typedef SW_RET (*SW_CFGM_SHOW_PROC)(SW_CFG cfg);

typedef struct _SW_CFGM_PROC
{
    SW_CFGM_OPEN_PROC open;
    SW_CFGM_CLOSE_PROC close;
    SW_CFGM_SAVE_PROC save;
    SW_CFGM_READ_PROC read;
    SW_CFGM_WRITE_PROC write;
    SW_CFGM_SHOW_PROC show;
}SW_CFGM_PROC;

SW_API SW_RET SW_InitCfgmAPI(SW_VOID);
SW_API SW_RET SW_RunCfgmAPI(SW_VOID);
SW_API SW_RET SW_StopCfgmAPI(SW_VOID);
SW_API SW_RET SW_ExitCfgmAPI(SW_VOID);
SW_API SW_CFGM SW_CreateCfgm(const SW_CHAR *pFileName, SW_CFGM_PROC *pProc, SW_BOOL autoFlush);
SW_API SW_CFGM SW_CreateDefCfgm(const SW_CHAR *pFileName, SW_CFGM_TYPE type, SW_BOOL autoFlush);
SW_API SW_RET SW_GetCfgmFileName(SW_CFGM cfgm, SW_CHAR *pFileName, SW_UINT32 fileNameLen);
SW_API SW_RET SW_SetCfgmFileName(SW_CFGM cfgm, const SW_CHAR *pFileName);
SW_API SW_RET SW_DeleteCfgm(SW_CFGM cfgm);
SW_API SW_RET SW_CreateCfgmItem(SW_CFGM cfgm, const SW_CHAR *pSection, const SW_CHAR *pKey, SW_MUTEX *pMtx, SW_VOID *pData, SW_UINT32 dataLen, SW_DATA_TYPE dataType);
SW_API SW_RET SW_DeleteCfgmItem(SW_CFGM cfgm, const SW_CHAR *pSection, const SW_CHAR *pKey);
SW_API SW_RET SW_DeleteCfgmItemAll(SW_CFGM cfgm);
SW_API SW_RET SW_FlushCfgm(SW_CFGM cfgm);
SW_API SW_RET SW_UpdateCfgm(SW_CFGM cfgm);
SW_API SW_RET SW_ShowCfgm(SW_CFGM cfgm);

#ifdef __cplusplus
}
#endif

#endif

